<?php
/**
 * String View Helper.
 * @package halo
 */

/**
 * String View Helper.
 *
 * Provides access to the strings for the application.
  * @package halo
 */
class halo_StringViewHelper {

    /**
     * @var halo_HttpRequest
     */
    private $httpRequest;

    /**
     * @var halo_HttpResponse
     */
    private $httpResponse;

    /**
     * @var hc_configuration_IConfiguration
     */
    private $stringConfiguration;

    /**
     * Constructor
     * @param halo_HttpRequest $httpRequest The request.
     * @param halo_HttpResponse $httpResponse The response.
     */
    public function __construct(halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
        $this->httpRequest = $httpRequest;
        $this->httpResponse = $httpResponse;
        $context = halo_DispatcherUtil::GET_CONTEXT($this->httpRequest);
        $this->stringConfiguration = $context->get('stringConfiguration');
    }
 
    /**
     * Safely print a string.
     * @param string $string String to print
     * @param boolean $htmlSafe Should the string be made HTML safe?
     * @see g
     */
    public function p($stringKey, $htmlSafe = null) {
        print $this->g($stringKey, $htmlSafe);
    }
   
    /**
     * Get a string.
     * @param string $string String to get
     * @param boolean $htmlSafe Should the string be made HTML safe?
     * @see p
     */
    public function g($stringKey, $htmlSafe = null) {
        $string = $this->stringConfiguration->exists($stringKey) ?
            $this->stringConfiguration->get($stringKey) :
            '${' . $stringKey . '}';
        if ( $htmlSafe === null or $htmlSafe ) $string = htmlspecialchars($string);
        return $string;
    }

}
?>
